﻿package com.yy.ui.containers {
    import flash.display.*;

    public class Tile extends Box {

        public static const HORIZONTAL:String = "horizontal";
        public static const VERTICAL:String = "vertical";

        private var _tileHeight:Number;
        private var _tileWidth:Number;
        private var _hCount:int;
        private var _vCount:int;
        private var _hGap:int;
        private var _vGap:int;
        private var _itemDirection:String;
        private var _pageDirection:String;
        private var _childChange:Boolean = false;

        public function Tile(_arg1:Number, _arg2:Number, _arg3:uint=2, _arg4:uint=2, _arg5:Number=0, _arg6:Number=0, _arg7:String="horizontal", _arg8:String="horizontal"){
            this._tileWidth = _arg1;
            this._tileHeight = _arg2;
            this._hCount = _arg3;
            this._vCount = _arg4;
            this._hGap = _arg5;
            this._vGap = _arg6;
            this._itemDirection = _arg7;
            this._pageDirection = _arg8;
        }
        override protected function updateDisplayList():void{
            super.updateDisplayList();
            this._updateChild();
        }
        private function _updateChild():void{
            if (this._childChange){
                this.updateChild();
                this._childChange = false;
            };
        }
        protected function updateChild():void{
            var _local10:DisplayObject;
            if ((((this._hCount == 0)) && ((this._vCount == 0)))){
                return;
            };
            var _local1:int = this.numChildren;
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:Number = (this._hCount * (this._tileWidth + this._hGap));
            var _local6:Number = (this._vCount * (this._tileHeight + this._vGap));
            var _local7:Number = (this._tileWidth + this._hGap);
            var _local8:Number = (this._tileHeight + this._vGap);
            var _local9:int;
            while (_local9 < _local1) {
                _local10 = getChildAt(_local9);
                if (_local10.visible == false){
                } else {
                    if (this._pageDirection == Tile.HORIZONTAL){
                        _local10.x = ((_local2 * _local7) + (_local4 * _local5));
                        _local10.y = (_local3 * _local8);
                    } else {
                        _local10.x = (_local2 * _local7);
                        _local10.y = ((_local3 * _local8) + (_local4 * _local6));
                    };
                    if (this._itemDirection == Tile.HORIZONTAL){
                        _local2++;
                        if (_local2 >= this._hCount){
                            _local2 = 0;
                            _local3++;
                            if (_local3 >= this._vCount){
                                _local3 = 0;
                                _local4++;
                            };
                        };
                    } else {
                        _local3++;
                        if (_local3 >= this._vCount){
                            _local3 = 0;
                            _local2++;
                            if (_local2 >= this._hCount){
                                _local2 = 0;
                                _local4++;
                            };
                        };
                    };
                };
                _local9++;
            };
        }
        override public function addChild(_arg1:DisplayObject):DisplayObject{
            var _local2:DisplayObject = super.addChild(_arg1);
            this._childChange = true;
            if (stage){
                stage.invalidate();
            };
            return (_local2);
        }
        override public function addChildAt(_arg1:DisplayObject, _arg2:int):DisplayObject{
            var _local3:DisplayObject = super.addChildAt(_arg1, _arg2);
            this._childChange = true;
            if (stage){
                stage.invalidate();
            };
            return (_local3);
        }
        override public function removeChild(_arg1:DisplayObject):DisplayObject{
            var _local2:DisplayObject = super.removeChild(_arg1);
            this._childChange = true;
            if (stage){
                stage.invalidate();
            };
            return (_local2);
        }
        override public function removeChildAt(_arg1:int):DisplayObject{
            var _local2:DisplayObject = super.removeChildAt(_arg1);
            this._childChange = true;
            if (stage){
                stage.invalidate();
            };
            return (_local2);
        }
        override public function setChildIndex(_arg1:DisplayObject, _arg2:int):void{
            super.setChildIndex(_arg1, _arg2);
            this._childChange = true;
            if (stage){
                stage.invalidate();
            };
        }
        override public function swapChildren(_arg1:DisplayObject, _arg2:DisplayObject):void{
            super.swapChildren(_arg1, _arg2);
            this._childChange = true;
            if (stage){
                stage.invalidate();
            };
        }
        override public function swapChildrenAt(_arg1:int, _arg2:int):void{
            super.swapChildrenAt(_arg1, _arg2);
            this._childChange = true;
            if (stage){
                stage.invalidate();
            };
        }

    }
}
